import { defineStore } from 'pinia'

export const useTicketStore = defineStore('tickets', {
  state: () => ({
    tickets: []
  }),
  actions: {
     // 新增异步初始化方法
    async initData() {
      // 模拟API请求延迟
      await new Promise(resolve => setTimeout(resolve, 300))
      
      this.tickets = [
        // 你提供的初始数据
        {
          id: "001",
          project: "Road Project A",
          overtime: true,
          hours: 3.5,
          created_at: "2024-04-10 10:30"
        },
        {
          id: "002",
          project: "Bridge Maintenance B",
          overtime: false,
          hours: 2,
          created_at: "2024-04-09 13:00"
        },
        {
          id: "003",
          project: "Pipeline Fix C",
          overtime: true,
          hours: 4.5,
          created_at: "2024-04-08 08:00"
        },
        {
          id: "004",
          project: "Tunnel Cleaning D",
          overtime: false,
          hours: 3,
          created_at: "2024-04-07 16:45"
        }

        // ...其他三个数据项
      ]
    },
    deleteTicket(id) {
      this.tickets = this.tickets.filter(t => t.id !== id)
    }
  }
})